Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

296
Vistas
"Method Not Allowed The method is not allowed for the requested URL" even with methods = ["POST"] enabled?

In a render.html file I have a button that calls a function in render.js (I included render.js as src in script)

<button type="button" onclick="someFunc()">Calculate</button>

In render.js someFunc() makes a request

options =  {
        method: "POST",
        headers: {
           "Content-Type" : "application/json"
        },
        body: JSON.stringify(feat1dataObj)
    }

    const test1 = await fetch('http://localhost:5000/analyzeInput', options)

app.py is the backend that should handle the request

from flask import Flask, jsonify, request

app = Flask(__name__);

@app.route('/analyzeInput', methods = ['POST'] )
def analyzeData(res):
    part1Len = request.json['part1Len']
    print(part1Len);
    res = jsonify( {"Testing":"1"} )
    res.headers.add('Access-Control-Allow-Origin', '*')
    res.headers.set('Access-Control-Allow-Methods', 'GET, POST')
    return res;


#start server
if __name__ == "__main__":
    app.run(debug=True);

But I get 405 ""Method Not Allowed The method is not allowed for the requested URL"; the typical solution is that method = ["POST"] is not included but I have that.

GitBash terminal Output

Seems like I'm making a GET request somehow?

Overall, I'm using ElectronJS to make a GUI, just trying to pass data from the GUI to Python script to process, not sure why tutorials recommend hosting; seems like there should be a way a much simpler way to do this.

EDIT:

@app.route('/analyzeInput', methods = ['GET', 'POST', 'OPTIONS'] )
#def analyzeData(res):
#def analyzeData(request):
def analyzeData():
  if request.method == 'POST': 
    print("entered analyzeInput")
    #part1Len = request.json['part1Len']
    #print(part1Len);
    res = jsonify( {"Testing":"1"} )
    res.headers.add('Access-Control-Allow-Origin', '*')
    #res.headers.set('Access-Control-Allow-Methods', 'GET, POST, OPTIONS')
    res.headers.add('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept')
    return res;

Code currently looks like this (I changed analyzeData to analyzeInput; and changed it everywhere so I don't worry about that part). Getting "view function for 'analyzeData' did not return a valid response. The function either returned None or ended without a return statement" as the internal server error.

Again, pretty sure that the problem is that the request is sent as "GET" not "POST" but cannot find an explanation for this. New output

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

It's cross site origin(CORS) issue. From your code I can see you have already taking care of that but in the app.route add options like this: @app.route('/analyzeInput', methods = ['POST', 'OPTIONS'] ) . The reason is that the browser rewrites the request and changes the request method to options in compliance to the cross site origin(CORS) policy that took effect in 2014.

about 4 years ago · Juan Pablo Isaza Denunciar

0

In addition to @john mba’s answer you should add mode: “cors” to your options

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda